// ----------------------------------------------------------------------------
/**
 * @file    client.h
 *
 * @brief   Header file for client.cpp
 *
 * The client class is the container for the socket of the user and allows the UI to communicate
 * with the server.
 *
 * @author  Siddharth Sathyam <ssathy2@gmail.com>
 * @author  Alan Ruvalcaba <aruval3@gmail.com>
 * @author  Patrick LaMontagna <plamontagna@gmail.com
 *
 * @version 1.0
 *
 * @date    November 24th, 2011
 *
 */
// ----------------------------------------------------------------------------

#ifndef CLIENT_H
#define CLIENT_H

#include <QtGui/QLabel>
#include <QTcpSocket>
#include <QtNetwork>
#include <QMessageBox>
#include <QObject>

/**
 * @class   Client
 *
 * @brief   The Client helper methods
 *
 */

class Client: public QObject
{
    Q_OBJECT
public:

    /// Default constructor
    /// @param address The address of the user
    /// @param port The port number of the user
    /// @param userName The username of the client
    Client(QString address, quint16 port, QString userName);

    /**
    * @brief Boolean method that returns a successful or failed connection
    */

    bool startClient();

    /**
    * @brief Method that gets the clients username
    * @return The clients username
    */

    QString getUserName();

    /**
    * @brief Method that gets the clients host address
    * @return The clients host address
    */

    QString getAddress();

    /**
    * @brief Method that gets the clients port
    * @return The clients port
    */

    quint16 getPort();

    /**
    * @brief Method that receives the message from the client
    * @return The message from the client
    */

    QString getMessage();

    /**
    * @brief Method that gets the users that are online
    * @return A list of online users
    */

    QStringList getOnlineList();

    /**
    * @brief Method that gets the clients QTcpSocket
    * @return The client value
    */

    QTcpSocket *getClient();

    /**
    * @brief Method that sends the message
    *
    * @param fromUsername The from user
    * @param toUsername The to user
    * @param message The chat message
    * @param timeSent The time the message was sent
    */

    void sendMessage(QString,QString,QString,QString);

signals:

    /**
    * @brief Signal that verifies the username
    *
    * @param userName The userName to be verified
    * @param isConfirmed The boolean value of the client
    */

    void usernameValidConfirmation(QString, bool);

    /**
    * @brief Signal that verifies if a friend exists
    *
    * @param friendToBeAdded The username of the friend
    * @param isConfirmed The boolean value of the confirmation
    */

    void friendExistsConfirmation(QString, bool);

    /**
    * @brief Signal that verifies if a friend exists to be removed
    *
    * @param friendToBeRemoved The username of the friend to be removed
    * @param isConfirmed The boolean value of the confirmation
    */

    void friendRemoveExistsConfirmation(QString, bool);

    /**
    * @brief Signal that sends the list of users
    *
    * @param updatedListOfUsersOnline The updated list of available online users
    */

    void signalUsers(QStringList);

    /**
    * @brief Slot that receives the message
    * @param fromUser the name of the user who sent message
    * @param toUser the name of the user receiving the message
    * @param message the message being sent
    * @param timeSent the time in which the message was sent
    */

    void receiveMessage(QString,QString,QString,QString);

    /**
    * @brief Signal that sends out a friend request
    *
    * @param requestingUser The username of the friend requesting the add action
    */

    void friendRequest(QString);

private:
    /// Create a client instance variable
    QTcpSocket *client;

    /// Create a port variable
    quint16 port;

    /// Create a string username variable
    QString userName;

    /// Create a string message variable
    QString message;

    /// IP address variable
    QString address;

    /// List of friends online variable
    QStringList onlineUsers;

public slots:

    /**
    * @brief Method that sends all the user information to the server
    */

    void sendUserInformation();


    /**
    * @brief Method that receives messages from the server
    */

    void readyRead();

private slots:

    /**
    * @brief Slot that deals with the user wanting to send a friend request
    *
    * @param buddy The username of the friend requesting the add action
    */

    void handleOutgoingFriendRequest(QString);

    /**
    * @brief Slot that deals with the user wanting to remove a friend
    *
    * @param personToRemove The username of the friend to be removed
    */

    void handleFriendRemoveRequest(QString);

    /**
    * @brief Slot that handles a friend request confirmation from the user
    *
    * @param personRequesting The username of the user requesting a friend
    * @param isFriend Boolean value to check if the user is already a friend
    */

    void handleFriendRequestConfirmation(QString, bool);
};

#endif // CLIENT_H
